package com.bibrApp.difu.fragment.account_mvp;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bibrApp.difu.actvity.chengjiao_mvp.ChengjiaoBean;
import com.bibrApp.difu.api.RetrofitNet;
import com.bibrApp.difu.base.BaseObserver;
import com.bibrApp.difu.base.BasePresenter;
import com.bibrApp.difu.fragment.heyuewallet_mvp.HeyueWalletBean;
import com.bibrApp.difu.fragment.heyuewallet_mvp.IHeyueWalletView;
import com.bibrApp.difu.utils.EncryptUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class AccountPresenter extends BasePresenter<IAccountView> {

    public AccountPresenter(Context context, IAccountView iView) {
        super(context, iView);
    }

    /**
     * "value":"287630", 余额
     *  "valueIn":"288960", 变动之后的前
     * @param publicKey
     */

    public void getBtcBlance(String type ,String publicKey) {
        RetrofitNet.getInstance().getApi(true)
                .getBtcBlance(type ,publicKey,"txs","used",String.valueOf(System.currentTimeMillis()))
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(o -> {
                    if (o != null) {
                        iView.successOfGetAssets(o);
                    }
                },throwable -> {
                    Log.d("dj",throwable.getMessage());
                });

    }

    /**
     * 获取汇率 默认为cny
     */
    public void getRate(String type ) {
        RetrofitNet.getInstance().getApi(true)
                .getRate(type ,String.valueOf(System.currentTimeMillis()))
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(o -> {
                    if (!TextUtils.isEmpty(o)) {
                        iView.successOfRate(o);
                    }
                },throwable -> {
                    Log.d("dj",throwable.getMessage());
                });

    }

    /**
     * "value":"287630", 余额
     *  "valueIn":"288960", 变动之后的前
     * @param address
     */

    public void getEthBlance(String type ,String address) {
        RetrofitNet.getInstance().getApi(true)
                .getEthBlance(type ,address,1,1000,"txs")
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(o -> {
                    if (o != null) {
                        iView.successOfGetAssets(o);
                    }
                },throwable -> {
                    Log.d("dj",throwable.getMessage());
                });

    }
}
